import { daFieldDTOMessage, dataAssert } from '@/pages/CodeTables/specification';
import { addDataAssert, getDataAssetDetail } from '@/api/test/index';
import { dataType } from '@/enums/statusEnum';

// 控制详情弹窗/新增--编辑抽屉
const dataAsset = reactive<{
  sdialog: boolean; //对话框
  drawer: boolean; //抽屉
}>({
  sdialog: false,
  drawer: false,
});

//详情弹窗内容信息
const tableData: dataAssert = reactive({
  daCode: '',
  daChName: '',
  daEnName: '',
  daDescribe: '',
  directoryNameList: [''],
  daFieldDTO: [],
});
//数据资产管理详情
const Details = async () => {
  const res = await getDataAssetDetail(tableData.daCode);
  res.dataAssertCodeDTOList.forEach((e: daFieldDTOMessage) => {
    e.dcDataType = dataType[+e.dcDataType];
    e.dcvalueRange = `${e.dcMinValue} - ${e.dcMaxValue}`;
  });
  tableData.daFieldDTO = res.dataAssertCodeDTOList as [];
  tableData.directoryNameList = res.directoryNameList;
};

//新增数据资产
const addNewDataAssert = async () => {
  await addDataAssert(tableData);
  console.log('新增成功');
};

//编辑数据资产

export function getDataAssetDetailHooks() {
  return {
    dataAsset,
    tableData,
    Details,
    addNewDataAssert,
  };
}
